/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package sv.com.globalsolutionslt.controlador;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import sv.com.globalsolutionslt.entidades.Habilidad;

/**
 *
 * @author karinaMelara
 */
@Stateless
public class HabilidadFacade extends AbstractFacade<Habilidad> {
    @PersistenceContext(unitName = "BoldeDeTrabajoPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public HabilidadFacade() {
        super(Habilidad.class);
    }
    
     public List<Habilidad> HabilidadActivo(Integer p, Integer c) {
       
        List<Habilidad> habilidades=null;
        if(c!=null){
            try {        
            String sql = "SELECT h FROM Habilidad h  WHERE h.idCategoria.idCategoria="+c+" and h.idHabilidad not in (SELECT d.idHabilidad.idHabilidad FROM DetalleHabilidades d where d.idPersona.idPersona="+p+")";           
            Query q = em.createQuery(sql);

            habilidades = q.getResultList();

            } catch (NoResultException e) {
                    System.out.println("Sin resultados");
            }        
        }

        return habilidades;
    }    
    
}
